package org.geowebcache.layer.wms;

import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geowebcache.GeoWebCacheDispatcher;
import org.geowebcache.conveyor.ConveyorTile;
import org.geowebcache.io.Resource;

/** Author: LuoHaoLun Email : 506503279@qq.com Date : 2020/8/7 */
class TransparentImage {

    private static Log log = LogFactory.getLog(TransparentImage.class);

    public static ConveyorTile process(ConveyorTile tile, Resource buffer, String name) {
        try {
            ReadableByteChannel channel =
                    Channels.newChannel(
                            GeoWebCacheDispatcher.class.getResourceAsStream("blank.png"));
            buffer.transferFrom(channel);
            tile.setBlob(buffer);
            //            TileObject tile1 =
            //                    TileObject.createCompleteTileObject(
            //                            name,
            //                            tile.getTileIndex(),
            //                            tile.getGridSetId(),
            //                            tile.getMimeType().getFormat(),
            //                            tile.getParameters(),
            //                            buffer);
            //            tile1.setCreated(System.currentTimeMillis());
            //            try {
            //                if (tile.isMetaTileCacheOnly()) {
            //                    tile.getStorageBroker().putTransient(tile1);
            //                } else {
            //                    tile.getStorageBroker().put(tile1);
            //                }
            //                tile.getStorageObject().setCreated(tile1.getCreated());
            //            } catch (StorageException e) {
            //                throw new GeoWebCacheException(e);
            //            }
            return tile;
        } catch (Exception e) {
            log.error("处理透明图片失败： " + e);
            e.printStackTrace();
        }
        return null;
    }
}
